package reflect;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.lang.reflect.Method;
import java.util.Properties;

public class ReflectUtil {

    public void react(String className,String methodName){
        try {
            Class aClass = Class.forName(className);
              /*  Method[] methods = aClass.getMethods();
               for (Method method:methods){
                if (!method.equals(methodName) || null == methodName) {
                    throw new Exception("参数不合法！");
                }
            }*/
            try {
                Method method = aClass.getMethod(methodName);
                Object obj = aClass.newInstance();
                method.invoke(obj);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Properties getProperties(String filePath){
        Properties properties = new Properties();
        FileReader fileInputStream = null;
        try {
            fileInputStream = new FileReader(filePath);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            properties.load(fileInputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return properties;
    }
}
